//
//  Func_iOS.m
//  Demo
//
//  Created by migame on 15/12/14.
//
//

#include "ShowItem.h"
#include "DownLoadCenter.h"
#include "Func_ios.h"


using namespace ui;




bool ShowItem::init()
{
    if( Node::init()==false )return false;
    for(int y=0;y<10;y++)
    {
        Node *root = CSLoader::createNode("csd/ImageBtn.csb");
        this->addChild(root);
        m_title = (Text*)root->getChildByName("title");
        m_img = (ImageView*)root->getChildByName("img");
    }
    return true;
}










void ShowItem::onClick(Button *btn, int x, int y)
{
    log("点击 单个Item ");
}


void ShowItem::setBindTaskId(int taskid)
{
    m_taskId = taskid;
    if(m_taskId==-1)
        this->setVisible(false);
}

void ShowItem::setIndex(int idx)
{
    m_index = idx;
}

int ShowItem::getIndex()
{
    return m_index;
}


void ShowItem::updateShow(__Dictionary *oneInfo)
{
    m_title->setString("");
    //----
    if(m_taskId==-1 || oneInfo==nullptr)
        this->setVisible(false);
    else if( oneInfo )
    {
        this->setVisible(true);
        int taskId = oneInfo->valueForKey(INFO_ONE_ID)->intValue();
        __String* title = (__String*)oneInfo->objectForKey(INFO_ONE_TITLE);
        __Array *ary_img = (__Array *)oneInfo->objectForKey(INFO_ONE_IMG_ARY);
        //
        m_title->setString( title->getCString() );
        // img tag=10 即为还没有设置过图片。
        std::string imgFile = DownLoadCenter::getNowWebImgFilePath(taskId, 0);
        if( FileUtils::getInstance()->isFileExist(imgFile)==true ){
            m_img->loadTexture(imgFile.c_str(), Button::TextureResType::LOCAL);
        }
        else{
            __String *imgUrl = (__String *)ary_img->getObjectAtIndex(0);
//            DownLoadCenter::getInstance()->addImgDown(taskId, 0, imgUrl->getCString() );
            log("需要先下载图片  ————  直接用调用 httpNode 的方式下载。");
        }
    }
}














